package com.mf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mf.entity.bo.EducationInfoBo;
import com.mf.entity.vo.EducationInfoVo;
import com.mf.mapper.EducationInfoMapper;

import com.mf.service.IEducationInfoService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.heollhai.common.utils.MybatisPlusUtils;
import io.github.heollhai.common.utils.VerifyUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现类
 *
 * @author mf
 * @since 2024-09-01
 */
@Service
public class EducationInfoServiceImpl extends ServiceImpl<EducationInfoMapper, EducationInfoBo> implements IEducationInfoService {
    @Resource
    private EducationInfoMapper educationInfoMapper;
    /**
     * 新增|编辑
     */
    @Override
    public Integer insert(EducationInfoVo educationInfoVo) {
        final EducationInfoBo educationInfoBo = new EducationInfoBo();
        BeanUtils.copyProperties(educationInfoVo, educationInfoBo);
        if(VerifyUtils.isEmpty(educationInfoVo.getId())){
            return educationInfoMapper.insert(educationInfoBo);
        }

        return educationInfoMapper.updateById(educationInfoBo);
    }


    /**
     * 查询
     */
    @Override
    public List<EducationInfoVo> listByRosterId(Integer rosterId) {
        final LambdaQueryWrapper<EducationInfoBo> queryWrapper = new LambdaQueryWrapper<EducationInfoBo>();
        queryWrapper.eq(EducationInfoBo::getRosterId, rosterId);
        return MybatisPlusUtils.changeDataClass(educationInfoMapper.selectList(queryWrapper), EducationInfoVo.class);
    }
}
